package java44th.group.service.admin.goods;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java44th.group.bean.admin.bo.goods.creategoods.AdminGoodsCreatePO;
import java44th.group.bean.admin.bo.goods.creategoods.AdminGoodsPO;
import java44th.group.bean.admin.bo.goods.creategoods.AdminGoodsProduct;
import java44th.group.bean.common.BasePageInfo;
import java44th.group.bean.common.BaseStringUtils;
import java44th.group.bean.common.CommonData;
import java44th.group.bean.po.*;
import java44th.group.bean.admin.vo.BaseRespVo;
import java44th.group.bean.admin.vo.goods.BrandPartVO;
import java44th.group.bean.admin.vo.goods.CatAndBrandDataVO;
import java44th.group.bean.admin.vo.goods.CategoryPartVO;
import java44th.group.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @projectName: project-second
 * @package: java44th.group.service.admin.goods
 * @className: AdminGoodsServiceImpl
 * @author: 杨浩祥
 * @description: TODO
 * @date: 2022/10/11 23:22
 * @version: 1.0
 */
@Service
public class AdminGoodsServiceImpl implements AdminGoodsService {

    @Autowired
    MarketGoodsMapper goodsMapper;

    @Autowired
    MarketBrandMapper brandMapper;

    @Autowired
    MarketCategoryMapper categoryMapper;

    @Autowired
    MarketGoodsAttributeMapper goodsAttributemapper;

    @Autowired
    MarketGoodsProductMapper goodsProductMapper;

    @Autowired
    MarketGoodsSpecificationMapper goodsSpecificationMapper;

    @Override
    public BaseRespVo list(Integer goodsId, String goodsSn, String name, BasePageInfo info) {
        // {"errno":0,"data":{"total":290,"pages":15,"limit":20,"page":1,"list":[{"id":1181090,"goodsSn":"123456","name":"海尔电视","categoryId":1008016,"brandId":1022000,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/r6l95lztazmtsq3wdrld.jpg","http://182.92.235.201:8083/wx/storage/fetch/7zrsd4yz31fy2vkckxrd.jpg"],"keywords":"电视","brief":"实在是好","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/a7xii1nxgmhodsswbqi7.jpg","isNew":true,"isHot":true,"unit":"件","counterPrice":5000.00,"retailPrice":0.00,"addTime":"2022-09-22 12:31:34","updateTime":"2022-09-22 12:31:34","deleted":false,"detail":"<p>世人用了都说好</p>"},{"id":1181089,"goodsSn":"123456","name":"液晶电视","categoryId":1011002,"brandId":1001010,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/18003vpdbddjgss998ks.jpg","http://182.92.235.201:8083/wx/storage/fetch/xu4b4co3p63ng55fx30x.jpg"],"keywords":"电视","brief":"实在是好","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/3rmemgju4vd83vayus7o.jpg","isNew":true,"isHot":false,"unit":"件","counterPrice":5000.00,"retailPrice":0.00,"addTime":"2022-09-21 22:49:02","updateTime":"2022-09-21 22:49:02","deleted":false,"detail":"<p>手动阀手动阀大是大非撒旦发射点发射点发</p>"},{"id":1181088,"goodsSn":"5436","name":"asdd","categoryId":1008007,"brandId":1001012,"gallery":[],"keywords":"","brief":"","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/iczb2q5o95e4l9z799gw.jpeg","shareUrl":"","isNew":true,"isHot":false,"unit":"’件‘","counterPrice":1231.00,"retailPrice":0.00,"addTime":"2022-09-13 12:11:06","updateTime":"2022-09-13 12:39:44","deleted":false},{"id":1181087,"goodsSn":"1612351","name":"asd","categoryId":0,"brandId":0,"gallery":[],"keywords":"","brief":"","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/wwkuab6xm9orhl35507y.jpeg","isNew":true,"isHot":false,"unit":"’件‘","counterPrice":999.00,"retailPrice":999.00,"addTime":"2022-09-13 12:08:25","updateTime":"2022-09-13 12:08:25","deleted":false},{"id":1181086,"goodsSn":"jadsdsa2","name":"手机","categoryId":1036064,"brandId":1046029,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/4yxjr4exng30d784gao1.jpg"],"keywords":"华为","brief":"华为牛逼","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/f0uzzuz0rw02ris2mw5a.jpeg","shareUrl":"","isNew":true,"isHot":true,"unit":"件","counterPrice":8888.00,"retailPrice":0.00,"addTime":"2022-09-13 11:54:03","updateTime":"2022-09-13 13:16:27","deleted":false,"detail":"<p>华为手机天下第一，5G牛逼！！！！！</p>"},{"id":1181085,"goodsSn":"111","name":"111","categoryId":1008008,"brandId":1001002,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/ozzxnvdza2jiap6wx4mr.jpg"],"keywords":"哈哈","brief":"1哈哈哈哈","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/bonazccbl0maembuooml.jpg","isNew":true,"isHot":false,"unit":"个","counterPrice":1111.00,"retailPrice":99.00,"addTime":"2022-09-13 11:51:03","updateTime":"2022-09-13 11:51:03","deleted":false,"detail":"<p>哈哈哈</p>"},{"id":1181082,"goodsSn":"1181038","name":"黑丝","categoryId":1008004,"brandId":1001007,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/tev35qeootwdtew54ze9.jpg"],"keywords":"","brief":"黑丝","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/zikpr1o6cowe09ngzmm0.jpg","shareUrl":"","isNew":true,"isHot":false,"unit":"件","counterPrice":300.00,"retailPrice":20.00,"addTime":"2022-09-12 15:56:41","updateTime":"2022-09-12 23:36:30","deleted":false,"detail":"<p>很骚</p>"},{"id":1181081,"goodsSn":"1181025","name":"西装","categoryId":1020009,"brandId":1001000,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/dj7j09sbf92taavqalvk.jpg"],"keywords":"帅","brief":"很帅","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/7ya8e0nsoce1252rovbl.jpg","isNew":true,"isHot":false,"unit":"个","counterPrice":999.00,"retailPrice":999.00,"addTime":"2022-09-12 15:52:19","updateTime":"2022-09-12 15:52:19","deleted":false,"detail":"<p>很棒哦铁子</p>"},{"id":1181080,"goodsSn":"345543","name":"阿帕奇直升机","categoryId":1036022,"brandId":1001008,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/3sgz6nievlhfeh0gaz5t.jpg"],"keywords":"阿帕奇，直升机","brief":"阿帕奇直升机，美国投降了，买回家给孩子当玩具吧","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/qrn5um95vjz9ipm0h1kw.jpg","shareUrl":"","isNew":true,"isHot":false,"unit":"架","counterPrice":3.77,"retailPrice":2.00,"addTime":"2022-09-12 15:08:12","updateTime":"2022-09-12 23:37:30","deleted":false,"detail":"<p>阿帕奇直升机，清仓大甩卖</p>"},{"id":1181079,"goodsSn":"3131","name":"测试1111111111","categoryId":0,"brandId":0,"gallery":[],"keywords":"","brief":"","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/dmwp10q2m6nf9o73mjbo.jpg","isNew":true,"isHot":false,"unit":"件","counterPrice":4000.00,"retailPrice":400.00,"addTime":"2022-09-12 12:03:17","updateTime":"2022-09-12 12:03:17","deleted":false},{"id":1181078,"goodsSn":"1","name":"goodsnamemonth","categoryId":1036066,"brandId":1046032,"gallery":[],"keywords":"month","brief":"商品简介month","isOnSale":true,"sortOrder":100,"picUrl":"","isNew":true,"isHot":false,"unit":"个","counterPrice":1.00,"retailPrice":7.00,"addTime":"2022-09-12 10:05:40","updateTime":"2022-09-12 10:05:40","deleted":false,"detail":"<p>商品详细介绍month</p>"},{"id":1181077,"goodsSn":"测试2","name":"这是商品测试名称","categoryId":1005002,"brandId":1001010,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/nfiwvclixqb4yi7hgdpz.jpg"],"keywords":"这是关键字","brief":"这是商品简介","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/8718ftzpkmactshaivkg.jpg","isNew":true,"isHot":false,"unit":"个","counterPrice":399.00,"retailPrice":0.00,"addTime":"2022-09-12 09:58:06","updateTime":"2022-09-12 09:58:06","deleted":false,"detail":"<p>这是商品详细介绍</p>\n<p><img src=\"http://182.92.235.201:8083/wx/storage/fetch/v8brshy3bc1gin2q1y1z.jpg\" alt=\"\" width=\"580\" height=\"580\" /></p>"},{"id":1181076,"goodsSn":"1324141","name":"12414","categoryId":1008002,"brandId":1001000,"gallery":[],"keywords":"你好","brief":"去","isOnSale":true,"sortOrder":100,"picUrl":"","isNew":true,"isHot":false,"unit":"件","counterPrice":100.00,"retailPrice":0.00,"addTime":"2022-09-12 09:54:04","updateTime":"2022-09-12 09:54:04","deleted":false},{"id":1181075,"goodsSn":"10030611","name":"这是名称（测试）","categoryId":1005002,"brandId":1001008,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/adkeif7k3ilp8rxx42zc.jpg"],"keywords":"这是关键字","brief":"这是商品简介","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/34zj1vd7yp3lahzajd8k.jpg","shareUrl":"","isNew":true,"isHot":false,"unit":"台","counterPrice":599.00,"retailPrice":299.00,"addTime":"2022-09-12 09:41:19","updateTime":"2022-09-12 09:42:37","deleted":false,"detail":"<p>这是商品详细介绍</p>\n<p><img src=\"http://182.92.235.201:8083/wx/storage/fetch/jzi8npmchvej455icamw.jpg\" alt=\"\" width=\"292\" height=\"224\" /></p>"},{"id":1181074,"goodsSn":"12341234","name":"goodsdetail测试","categoryId":1008002,"brandId":1001010,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/y7ehtvuc2tz40kdx9uev.jpg","http://182.92.235.201:8083/wx/storage/fetch/7vblwwymqk1ugl8e3x2j.png"],"keywords":"吉他谱","brief":"测试","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/3i6uwaskd34lr8w3xz7z.png","isNew":true,"isHot":false,"unit":"个","counterPrice":100.00,"retailPrice":50.00,"addTime":"2022-09-12 09:28:26","updateTime":"2022-09-12 09:28:26","deleted":false,"detail":"<p>测试</p>"},{"id":1181073,"goodsSn":"7654321","name":"保时捷","categoryId":1036021,"brandId":1001000,"gallery":["http://182.92.235.201:8083/wx/storage/fetch/v2fn6jmnsk267y7cc1aq.jpg"],"keywords":"loser必备","brief":"保时捷，loser身份的象征","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/te1gz2kztteau8uf627g.jpg","shareUrl":"","isNew":false,"isHot":true,"unit":"辆","counterPrice":2.89,"retailPrice":1.99,"addTime":"2022-09-11 19:23:09","updateTime":"2022-09-12 12:04:18","deleted":false,"detail":"<p>保时捷，清仓大甩卖</p>"},{"id":1181072,"goodsSn":"23232342343","name":"白菜","categoryId":1036049,"brandId":1001000,"gallery":[],"keywords":"","brief":"","isOnSale":true,"sortOrder":100,"picUrl":"http://182.92.235.201:8083/wx/storage/fetch/wxs71b9m0vlwys7m832d.jpg","shareUrl":"","isNew":true,"isHot":false,"unit":"件","counterPrice":8.00,"retailPrice":5.00,"addTime":"2022-09-11 13:29:10","updateTime":"2022-09-11 19:16:33","deleted":false},{"id":1181068,"goodsSn":"2214234","name":"goodsname","categoryId":0,"brandId":0,"gallery":[],"keywords":"","brief":"","isOnSale":true,"sortOrder":100,"picUrl":"","isNew":true,"isHot":false,"unit":"’件‘","counterPrice":0.00,"retailPrice":0.00,"addTime":"2022-09-11 11:21:52","updateTime":"2022-09-11 11:21:52","deleted":false},{"id":1181067,"goodsSn":"123","name":"zxcvbnm","categoryId":1008002,"brandId":1001000,"gallery":[],"keywords":"qqq","brief":"简介","isOnSale":true,"sortOrder":100,"picUrl":"","isNew":true,"isHot":true,"unit":"件","counterPrice":1024.00,"retailPrice":2048.00,"addTime":"2022-09-11 10:26:05","updateTime":"2022-09-11 10:26:05","deleted":false},{"id":1181066,"goodsSn":"1","name":"goods name","categoryId":0,"brandId":1046032,"gallery":[],"keywords":"","brief":"","isOnSale":false,"sortOrder":100,"picUrl":"","isNew":false,"isHot":false,"unit":"’件‘","counterPrice":0.00,"retailPrice":0.00,"addTime":"2022-09-11 00:55:00","updateTime":"2022-09-11 00:55:00","deleted":false}]},"errmsg":"成功"}
        MarketGoodsExample example = new MarketGoodsExample();
        MarketGoodsExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (info.getLimit() == 0) {
            List<MarketGoods> list = goodsMapper.selectByExample(example);
            CommonData<MarketGoods> marketGoodsCommonData = new CommonData<>();
            marketGoodsCommonData.setLimit(0);
            marketGoodsCommonData.setPage(0);
            marketGoodsCommonData.setPages(0);
            marketGoodsCommonData.setTotal(list.size());
            marketGoodsCommonData.setList(list);
            return BaseRespVo.ok
                    (marketGoodsCommonData);
        }
        PageHelper.startPage(info.getPage(), info.getLimit());

        if (goodsId != null) {
            criteria.andIdEqualTo(goodsId);
        }
        if (!BaseStringUtils.isEmpty(goodsSn)) {
            criteria.andGoodsSnEqualTo(goodsSn);
        }
        if (!BaseStringUtils.isEmpty(name)) {
            criteria.andNameLike("%" + name + "%");
        }
        example.setOrderByClause(info.getSort() + " " + info.getOrder());
        List<MarketGoods> list = goodsMapper.selectByExample(example);
        PageInfo<MarketGoods> pageInfo = new PageInfo<>(list);
        CommonData<MarketGoods> data = CommonData.data(pageInfo);
        return BaseRespVo.ok(data);
    }

    @Override
    public BaseRespVo catAndBrand() {
        // http://182.92.235.201:8083/admin/goods/catAndBrand
        // {"errno":0,"data":{"categoryList":[{"value":1005000,"label":"345345","children":[{"value":1008002,"label":"布艺软装"},{"value":1008008,"label":"被枕"},{"value":1008009,"label":"床品件套"},{"value":1008016,"label":"灯具"},{"value":1010003,"label":"地垫"},{"value":1011003,"label":"床垫"},{"value":1011004,"label":"家饰"},{"value":1015000,"label":"家具"},{"value":1017000,"label":"宠物"},{"value":1036000,"label":"夏凉"},{"value":1036053,"label":"123"},{"value":1036067,"label":"del1"},{"value":1036068,"label":"del2"},{"value":1036069,"label":"del3"},{"value":1036070,"label":"del4"},{"value":1036074,"label":"篮球二"}]},{"value":1008000,"label":"配件","children":[{"value":1008003,"label":"鞋"},{"value":1008007,"label":"围巾件套"},{"value":1008010,"label":"拖鞋"},{"value":1008018,"label":"单肩包"},{"value":1010004,"label":"双肩包"},{"value":1012001,"label":"功能箱包"},{"value":1013000,"label":"靴"},{"value":1020008,"label":"配饰"},{"value":1022000,"label":"数码"}]},{"value":1010000,"label":"服装","children":[{"value":1008004,"label":"袜子"},{"value":1010001,"label":"内衣"},{"value":1010002,"label":"内裤"},{"value":1013006,"label":"家居服"},{"value":1015001,"label":"T恤"},{"value":1020009,"label":"外衣"},{"value":1020010,"label":"衬衫"},{"value":1034000,"label":"丝袜"},{"value":1035000,"label":"卫衣"},{"value":1035001,"label":"毛衣"},{"value":1035002,"label":"裤装"}]},{"value":1011000,"label":"婴童","children":[{"value":1011001,"label":"妈咪"},{"value":1020003,"label":"服饰"},{"value":1020004,"label":"婴童洗护"},{"value":1020005,"label":"寝居"},{"value":1020006,"label":"玩具"},{"value":1020007,"label":"喂养"},{"value":1034001,"label":"童车童椅"}]},{"value":1012000,"label":"杂货","children":[{"value":1008005,"label":"户外"},{"value":1008006,"label":"口罩"},{"value":1008017,"label":"收纳"},{"value":1011002,"label":"海外"},{"value":1012002,"label":"雨具"},{"value":1012003,"label":"文具"},{"value":1020000,"label":"出行用品"},{"value":1021000,"label":"节日礼盒"},{"value":1036001,"label":"眼镜"},{"value":1036002,"label":"汽车用品"}]},{"value":1013001,"label":"洗护","children":[{"value":1008001,"label":"毛巾"},{"value":1009000,"label":"日用清洁"},{"value":1013002,"label":"美妆"},{"value":1013003,"label":"护发"},{"value":1013004,"label":"香薰"},{"value":1020001,"label":"面部护理"},{"value":1020002,"label":"用具"}]},{"value":1019000,"label":"志趣","children":[{"value":1018000,"label":"夏日甜心"},{"value":1025000,"label":"礼品卡"},{"value":1028001,"label":"唱片"},{"value":1032000,"label":"魔兽世界"},{"value":1032001,"label":"炉石传说"},{"value":1032002,"label":"守望先锋"},{"value":1032003,"label":"暗黑破坏神III"},{"value":1032004,"label":"星际争霸II"},{"value":1032005,"label":"风暴英雄"},{"value":1033000,"label":"梦幻西游"},{"value":1036004,"label":"大话西游"},{"value":1036028,"label":"电影票"}]},{"value":1036015,"label":"手机","children":[]},{"value":1036020,"label":"电脑","children":[]},{"value":1036023,"label":"坦克","children":[]},{"value":1036025,"label":"运动器具","children":[]},{"value":1036026,"label":"房产","children":[]},{"value":1036032,"label":"iii","children":[]},{"value":1036035,"label":"医药","children":[]},{"value":1036038,"label":"能源","children":[]},{"value":1036046,"label":"蔬菜大棚","children":[{"value":1036049,"label":"时蔬"},{"value":1036054,"label":"生鲜"}]},{"value":1036057,"label":"健身","children":[]},{"value":1036059,"label":"交通工具","children":[{"value":1036021,"label":"跑车"},{"value":1036022,"label":"飞机"}]},{"value":1036061,"label":"食品","children":[]},{"value":1036063,"label":"中秋快乐","children":[{"value":1036064,"label":"中秋看看华为手机"},{"value":1036065,"label":"中秋快乐看看女神"},{"value":1036066,"label":"中秋快乐看看月亮"}]},{"value":1036073,"label":"篮球","children":[]}],"brandList":[{"value":1001000,"label":"MUJI制造商"},{"value":1001002,"label":"内野制造商"},{"value":1001003,"label":"Adidas制造商"},{"value":1001007,"label":"优衣库制造商"},{"value":1001008,"label":"膳魔师制造商"},{"value":1001010,"label":"星巴克制造商"},{"value":1001012,"label":"Wedgwood制造商"},{"value":1001013,"label":"Royal Doulton制造商"},{"value":1001015,"label":"日本KEYUCA制造商"},{"value":1001016,"label":"爱慕制造商"},{"value":1001020,"label":"Ralph Lauren制造商"},{"value":1001037,"label":"新秀丽制造商"},{"value":1001038,"label":"Coach制造商"},{"value":1001039,"label":"MK制造商"},{"value":1001045,"label":"罗莱制造商"},{"value":1003000,"label":"Carters制造商"},{"value":1005001,"label":"Goody制造商"},{"value":1006000,"label":"范思哲制造商"},{"value":1008000,"label":"WPC制造商"},{"value":1010001,"label":"竹宝堂制造商"},{"value":1010002,"label":"资生堂制造商"},{"value":1015000,"label":"NITORI制造商"},{"value":1016002,"label":"HUGO BOSS制造商"},{"value":1018000,"label":"Sperry制造商"},{"value":1021000,"label":"Marc Jacobs制造商"},{"value":1022000,"label":"UGG制造商"},{"value":1022001,"label":"Palladium制造商"},{"value":1023000,"label":"PetitBateau小帆船制造商"},{"value":1024000,"label":"WMF制造商"},{"value":1024001,"label":"OBH制造商"},{"value":1024003,"label":"Stoneline制造商"},{"value":1024006,"label":"KitchenAid制造商"},{"value":1025000,"label":"Timberland制造商"},{"value":1026000,"label":"CK制造商"},{"value":1026001,"label":"Under Armour制造商"},{"value":1028000,"label":"Gucci制造商"},{"value":1028003,"label":"Burberry制造商"},{"value":1033004,"label":"爱马仕集团制造商"},{"value":1034001,"label":"Alexander McQueen制造商"},{"value":1037000,"label":"厚木ATSUGI制造商"},{"value":1038000,"label":"Birkenstock集团制造商"},{"value":1038001,"label":"Nine West制造商"},{"value":1039000,"label":"TEFAL制造商"},{"value":1039001,"label":"京瓷制造商"},{"value":1040000,"label":"Tescom制造商"},{"value":1041000,"label":"BCBG制造商"},{"value":1046000,"label":"Police制造商"},{"value":1046005,"label":"WTF"},{"value":1046006,"label":"WTF"},{"value":1046007,"label":"雪花2"},{"value":1046010,"label":"码表"},{"value":1046011,"label":"aa"},{"value":1046015,"label":"水电费水电费地方"},{"value":1046016,"label":"胜多负少的非"},{"value":1046021,"label":"123"},{"value":1046023,"label":"11"},{"value":1046024,"label":"喵内"},{"value":1046026,"label":"brand-test-09091707"},{"value":1046027,"label":"我爱刘亦菲"},{"value":1046029,"label":"刘亦菲最美"},{"value":1046031,"label":"洛琪希"},{"value":1046032,"label":"testbrand101"},{"value":1046033,"label":"111"},{"value":1046044,"label":"名称"}]},"errmsg":"成功"}
        List<BrandPartVO> brandList = brandMapper.selectAllIdAndName();
        List<CategoryPartVO> categoryList = categoryMapper.selectAllIdAndName();
        CatAndBrandDataVO catAndBrandDataVO = new CatAndBrandDataVO(categoryList, brandList);
        return BaseRespVo.ok(catAndBrandDataVO);

    }

    @Transactional
    @Override
    public BaseRespVo create(AdminGoodsCreatePO createPO) {
        // 必须参数为空
        // {"errno":401,"errmsg":"参数不对"}

        // 商品名字重复
        //  {"errno":611,"errmsg":"商品名已经存在"}

        //
        AdminGoodsPO goods = createPO.getGoods();
        if (BaseStringUtils.isEmpty(goods.getName()) || BaseStringUtils.isEmpty(goods.getGoodsSn())) {
            return BaseRespVo.falseParameter();
        }

        MarketGoodsExample example = new MarketGoodsExample();
        MarketGoodsExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsSnEqualTo(goods.getGoodsSn());
        List<MarketGoods> marketGoodsList = goodsMapper.selectByExample(example);
        if (marketGoodsList.size() > 0) {
            return BaseRespVo.complicatedParameter("商品名已经存在");
        }
        // MarketGoods marketGoods = transferAdminGoodsPOToMarketGoods(goods);

        List<AdminGoodsProduct> productsList = createPO.getProducts();
        BigDecimal retailPrice = productsList.get(0).getPrice();
        BigDecimal counterPrice = goods.getCounterPrice();

        if (retailPrice != null && retailPrice.doubleValue() < 0 ){
            return BaseRespVo.falseParameter402("价格不能为负数");
        }
        if (counterPrice != null && counterPrice.doubleValue() < 0){
            return BaseRespVo.falseParameter402("价格不能为负数");
        }
        // if(retailPrice != null && counterPrice != null){
        //     if ((retailPrice.doubleValue() < 0) || (counterPrice.doubleValue() < 0)) {
        //         return BaseRespVo.falseParameter402("价格不能为负数");
        //     }
        // }

        if (productsList.get(0).getNumber() < 0) {
            return BaseRespVo.falseParameter402("库存不能为负数");
        }


        goods.setRetailPrice(retailPrice);
        goods.setAddTime(new Date());
        goodsMapper.insertByAdminGoodsPO(goods);
        Integer goodsId = goods.getId();

        List<MarketGoodsAttribute> attributesList = createPO.getAttributes();
        for (MarketGoodsAttribute marketGoodsAttribute : attributesList) {
            marketGoodsAttribute.setAddTime(new Date());
            marketGoodsAttribute.setGoodsId(goodsId);
            goodsAttributemapper.insert(marketGoodsAttribute);
        }

        for (AdminGoodsProduct product : productsList) {
            product.setAddTime(new Date());
            product.setGoodsId(goodsId);
            goodsProductMapper.insertByAdminGoodsProduct(product);
        }
        List<MarketGoodsSpecification> specificationsList = createPO.getSpecifications();
        for (MarketGoodsSpecification specification : specificationsList) {
            specification.setGoodsId(goodsId);
            specification.setAddTime(new Date());
            goodsSpecificationMapper.insert(specification);
        }
        return BaseRespVo.ok();
    }

    @Override
    public BaseRespVo detail(Integer id) {
        AdminGoodsPO adminGoodsPO = goodsMapper.selectByPrimaryKeyToAdminGoodsPO(id);

        Integer categoryPid = adminGoodsPO.getCategoryId();
        Integer categoryId = categoryMapper.selectIdByPid(categoryPid);

        MarketGoodsAttributeExample attributeExample = new MarketGoodsAttributeExample();
        MarketGoodsAttributeExample.Criteria criteria = attributeExample.createCriteria();
        criteria.andGoodsIdEqualTo(id);
        List<MarketGoodsAttribute> attributeList = goodsAttributemapper.selectByExample(attributeExample);

        MarketGoodsSpecificationExample specExample = new MarketGoodsSpecificationExample();
        specExample.createCriteria().andGoodsIdEqualTo(id);
        List<MarketGoodsSpecification> specList = goodsSpecificationMapper.selectByExample(specExample);

        List<AdminGoodsProduct> productList = goodsProductMapper.selectAdminGoodsProductByGoodsId(id);

        AdminGoodsCreatePO adminGoodsCreatePO = new AdminGoodsCreatePO(adminGoodsPO, specList, productList, attributeList, new Integer[]{categoryId, categoryPid});

        return BaseRespVo.ok(adminGoodsCreatePO);
    }

    @Transactional
    @Override
    public BaseRespVo update(AdminGoodsCreatePO createPO) {
        // {"goods":{"id":1181006,"goodsSn":"123123222","name":"神奇baby","categoryId":1015001,"brandId":1001007,"gallery":["http://localhost:8083/pic/img/2899462b-27b5-459f-8f5b-a8644bebb8e1-神奇宝贝.jpg","http://localhost:8083/pic/img/2d8b887b-1da4-48ba-900d-278db1d3498f-神奇宝贝.jpg","http://localhost:8083/pic/img/c2f0f170-fa7e-4960-8ecb-d976a6988d5b-神奇宝贝.jpg","http://localhost:8083/pic/img/9f030d3a-52f4-4343-a2ed-7e114a2d8ed1-神奇宝贝.jpg"],"keywords":"kawaiii,555","brief":"可爱的yy","isOnSale":false,"sortOrder":100,"picUrl":"http://localhost:8083/pic/img/2c4d9a25-f3b1-4234-b524-d65abf5dd2f6-神奇宝贝.jpg","shareUrl":null,"isNew":false,"isHot":true,"unit":"件","counterPrice":"10000111111","retailPrice":null,"addTime":"2022-10-12","updateTime":null,"deleted":false,"detail":"<p>买不了吃亏，买买买</p>"},"specifications":[{"id":250,"goodsId":1181006,"specification":"大码","value":"1222","picUrl":"http://localhost:8083/pic/img/4011f48e-23de-427b-b9c8-0d59f6434a89-神奇宝贝.jpg","addTime":"2022-10-12","updateTime":null,"deleted":false}],"products":[{"id":251,"goodsId":1181006,"specifications":["1222"],"price":402,"number":100,"url":"http://localhost:8083/pic/img/1aaa446d-1f8c-456f-b17c-5c77c6acc115-神奇宝贝.jpg","addTime":"2022-10-12","updateTime":null,"deleted":false}],"attributes":[{"attribute":"准准标","value":"123131"},{"id":878,"goodsId":1181006,"attribute":"标准准","value":"10022","addTime":"2022-10-12","updateTime":null,"deleted":false}]}
        // {"errno":0,"errmsg":"成功"}
        AdminGoodsPO goods = createPO.getGoods();
        List<AdminGoodsProduct> productList = createPO.getProducts();
        Integer goodsId = goods.getId();
        goods.setUpdateTime(new Date());
        BigDecimal retailPrice = productList.get(0).getPrice();
        BigDecimal counterPrice = goods.getCounterPrice();
        if ((retailPrice.doubleValue() < 0) || (counterPrice.doubleValue() < 0)) {
            return BaseRespVo.falseParameter402("价格不能为负数");
        }
        if (productList.get(0).getNumber() < 0) {
            return BaseRespVo.falseParameter402("库存不能为负数");
        }

        goods.setRetailPrice(retailPrice);
        goodsMapper.updateByAdminGoodsPOSelective(goods);

        List<MarketGoodsSpecification> specList = createPO.getSpecifications();
        for (MarketGoodsSpecification specification : specList) {
            if (specification.getId() == null) {
                specification.setGoodsId(goodsId);
                specification.setAddTime(new Date());
                goodsSpecificationMapper.insert(specification);
                continue;
            }
            specification.setUpdateTime(new Date());
            goodsSpecificationMapper.updateByPrimaryKeySelective(specification);
        }


        for (AdminGoodsProduct product : productList) {
            if (product.getId() == null) {
                product.setGoodsId(goodsId);
                product.setAddTime(new Date());
                goodsProductMapper.insertByAdminGoodsProduct(product);
                continue;
            }
            product.setUpdateTime(new Date());
            goodsProductMapper.updateByAdminGoodsProductSelective(product);
        }

        List<MarketGoodsAttribute> attributeList = createPO.getAttributes();
        for (MarketGoodsAttribute marketGoodsAttribute : attributeList) {
            if (marketGoodsAttribute.getId() == null) {
                marketGoodsAttribute.setGoodsId(goodsId);
                marketGoodsAttribute.setAddTime(new Date());
                goodsAttributemapper.insert(marketGoodsAttribute);
                continue;
            }
            marketGoodsAttribute.setUpdateTime(new Date());
            goodsAttributemapper.updateByPrimaryKeySelective(marketGoodsAttribute);
        }

        return BaseRespVo.ok();
    }

    @Transactional
    @Override
    public BaseRespVo delete(MarketGoods goodsPO) {
        goodsPO.setDeleted(true);
        goodsMapper.updateByPrimaryKey(goodsPO);
        return BaseRespVo.ok();
    }

    // private MarketGoods transferAdminGoodsPOToMarketGoods(AdminGoodsPO adminGoodsPO) {
    //     MarketGoods marketGoods = new MarketGoods();
    //     marketGoods.setAddTime(new Date());
    //     marketGoods.setBrandId(adminGoodsPO.getBrandId());
    //     marketGoods.setBrief(adminGoodsPO.getBrief());
    //     marketGoods.setPicUrl(adminGoodsPO.getPicUrl());
    //     marketGoods.setIsHot(adminGoodsPO.getIsHot());
    //     marketGoods.setIsOnSale(adminGoodsPO.getIsOnSale());
    //     marketGoods.setGoodsSn(adminGoodsPO.getGoodsSn());
    //     marketGoods.setName(adminGoodsPO.getName());
    //     marketGoods.setUnit(adminGoodsPO.getUnit());
    //     marketGoods.setKeywords(adminGoodsPO.getKeywords());
    //     marketGoods.setCategoryId(adminGoodsPO.getCategoryId());
    //     marketGoods.setDetail(adminGoodsPO.getDetail());
    //     // marketGoods.setGallery();
    //
    //     return null;
    // }
}
